package com.demo.netty;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.local.DefaultLocalServerChannelFactory;
import org.jboss.netty.channel.local.LocalAddress;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author jasper
 */
public class ServertStart {

	public static void main(String[] args) {
		// 服务类
		ServerBootstrap bootstrap = new ServerBootstrap();
		// boss线程监听端口，worker线程负责数据读写
		ExecutorService boss = Executors.newCachedThreadPool();
		ExecutorService worker = Executors.newCachedThreadPool();
		// 设置niosocket工厂
		bootstrap.setFactory(new DefaultLocalServerChannelFactory());
		// 设置管道的工厂
//		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
//			@Override
//			public ChannelPipeline getPipeline() throws Exception {
//				ChannelPipeline pipeline = Channels.pipeline();
//				pipeline.addLast("decoder", new StringDecoder());
//				pipeline.addLast("encoder", new StringEncoder());
//				pipeline.addLast("serverHandler", new ServerHandler());
//				return pipeline;
//			}
//		});
//		bootstrap.setOption("reuseAddress", true);
        bootstrap.getPipeline().addLast("serverHandler",new ServerHandler());
		bootstrap.bind(new LocalAddress(10081));
		System.out.println("server start on 10081");
	}
}